package TreeSeries;

import java.util.LinkedList;
import java.util.Queue;

public class MaxDepthSolution_104 {
    public int maxDepth_LevelOrder(TreeNode root) {
        // 使用层序遍历
        int result = 0;
        Queue<TreeNode> queue = new LinkedList<>();
        if (root == null) {
            return result;
        }

        queue.offer(root);
        while (!queue.isEmpty()) {
            int len = queue.size();
            for (int i = 0; i < len; i++) {
                TreeNode tempNode = queue.poll();
                if (tempNode.left != null) queue.offer(tempNode.left);
                if (tempNode.right != null) queue.offer(tempNode.right);
            }
            result++;
        }
        return result;
    }

    public int maxDepth_DFS(TreeNode root) {
        if (root == null) {
            return 0;
        } else {
            int leftDepth = maxDepth_DFS(root.left);
            int rightDepth = maxDepth_DFS(root.right);

            return Math.max(leftDepth, rightDepth) + 1;
        }
    }
}
